package com.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.Socket.WebSocket;

@SuppressWarnings("serial")
public class CheckServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
		String hint="";
		Map<String,WebSocket> clients=WebSocket.getClients();
		if(name.isEmpty())
			hint="请输入用户名！";
		else if(clients.get(name)!=null)
			hint="用户名已存在！";
		
		out.print(hint);
		out.flush();
		out.close();
	}

}
